package com.ruoyi.project.purchase.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.purchase.domain.P_drug;
import com.ruoyi.project.purchase.domain.Purch_drug;
import com.ruoyi.project.purchase.domain.Purchase;
import com.ruoyi.project.purchase.domain.VO;
import com.ruoyi.project.purchase.service.Purch_drugService;
import com.ruoyi.project.purchase.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Purch_drug/detail/")
public class Purch_drugController extends BaseController {
    @Autowired
    private Purch_drugService purch_drugService;

    @RequestMapping("/findAllDrugByPurOrderId/{purOrderId}")
    public TableDataInfo findAllDrugByPurOrderId (@PathVariable String purOrderId){
        List<Purch_drug> allDrugByPurOrderId = purch_drugService.findAllDrugByPurOrderId(purOrderId);
        return getDataTable(allDrugByPurOrderId);
    }

    @RequestMapping("/findAllType")
    public AjaxResult findAllType (){
        List<P_drug> allType = purch_drugService.findAllType();
        return AjaxResult.success(allType);
    }

    @RequestMapping("/findAllDrug/{showedDrugIds}")
    public TableDataInfo findAllDrug (P_drug p_drug,@PathVariable Integer [] showedDrugIds){
        System.out.println(showedDrugIds.toString());
        startPage();
        List<P_drug> allDrug = purch_drugService.findAllDrug(p_drug,showedDrugIds);
        return getDataTable(allDrug);
    }

    @RequestMapping("/sureDrug")
    public AjaxResult sureDrug (@RequestBody VO vo){
        System.out.println(vo);
        System.out.println(vo.getPurOrderId());
        int i = purch_drugService.addDrugPur(vo);
        return toAjax(i);
    }

    @RequestMapping("/deletePurDrug/{drugId}")
    public AjaxResult deletePurDrug (@PathVariable Integer drugId , Purchase purchase){
        int i = purch_drugService.deletePurDrug(drugId, purchase);
        return toAjax(i);
    }
}
